package com.leyou.search.web;


import com.leyou.common.vo.PageResult;
import com.leyou.search.dto.GoodsDTO;
import com.leyou.search.dto.SearchRequest;
import com.leyou.search.service.SearchService;
import jdk.nashorn.internal.ir.RuntimeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class SearchController {

    @Autowired
    private SearchService searchService;  //传入 SpuDTO 对象，查询数据库并返回 Goods对象

    /**
     * 分页查询
     * @param request
     * @return
     */
    @PostMapping("/page")
    public ResponseEntity<PageResult<GoodsDTO>> search(@RequestBody SearchRequest  request){
     return ResponseEntity.ok(searchService.search(request));
    }

    /**
     * 根据查询条件key，聚合查询分类与品牌信息
     * @param request
     * @return
     */
    @PostMapping("/filter")
    public ResponseEntity<Map<String, List<?>>> queryFilters(@RequestBody SearchRequest request){
        return ResponseEntity.ok().body(searchService.queryFilters(request));
    }
}
